package com.bytedance.scenedemo.navigation.push_singletop;

import com.bytedance.scene.Scene;
import com.bytedance.scene.interfaces.PushOptions;
import com.bytedance.scene.ktx.SceneExtensions;
import com.bytedance.scenedemo.ResourceTable;
import com.bytedance.scenedemo.utility.ColorUtil;
import ohos.aafwk.content.Intent;
import ohos.agp.components.*;

/**
 * Created by JiangQi on 8/2/18.
 */
public class PushSingleTopScene_1 extends Scene {
    @Override
    public Component onCreateView(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        Component layout=scatter.parse(ResourceTable.Layout_push_single_to_root_scene,container,false);
        ScrollView svMain= (ScrollView) layout.findComponentById(ResourceTable.Id_sv_single_to_root_scene_main);
        Text textHint= (Text) layout.findComponentById(ResourceTable.Id_text_single_to_root_scene_hint);
        Text textPath= (Text) layout.findComponentById(ResourceTable.Id_text_single_to_root_scene_path);
        Button btnGoTo= (Button) layout.findComponentById(ResourceTable.Id_btn_single_to_root_scene_goto);

        svMain.setBackground(ColorUtil.getMaterialColor(2));
        textHint.setText(getClassName());
        textPath.setText(SceneExtensions.getNavigationScene(this).getStackHistory());

        btnGoTo.setText("点击跳到 PushSingleTopScene_1");
        btnGoTo.setClickedListener(component -> {
            PushOptions options = new PushOptions.Builder()
                    .setRemovePredicate(new PushOptions.SingleTopPredicate(PushSingleTopScene_1.class))
                    .build();
            if(SceneExtensions.getNavigationScene(this)!=null){
                SceneExtensions.getNavigationScene(this).push(PushSingleTopScene_1.class,null,options);
            }
        });

        return layout;
    }

}
